############################################################################
def enumerate_function(sequence, start=0):
    n = start
    for elem in sequence:
        yield n, elem
        n += 1

seasons          = ['Spring', 'Summer', 'Fall', 'Winter']

generator_season = enumerate_function(seasons)

print [generator_season.next(),generator_season.next(),generator_season.next(),generator_season.next()]
print list(enumerate_function(seasons))
print list(enumerate(seasons, start=1))

############################################################################
def make_counter(x):
    print 'entering make_counter'
    while 1:
        yield x               
        print 'incrementing x', x
        x = x + 1
        
#return genearator object
generator = make_counter(3)
print generator
#call function to first yield instruction -> entering make_counter
generator.next()
#call function when function was terminated -> print incrementing x
generator.next()
generator.next()
generator.next()

############################################################################
def static_num2():
    k = 0
    while True:
        k += 1
        yield k

#zwraca generator
static_generator = static_num2()
for i in range(0,30) :
    print static_generator.next()  

############################################################################
def iterquad ():
    for i in range(5):
        yield (i*i)

#iterquad() zwraca generator
for j in iterquad():
    print j
